<?php

// Prevent individual file access
if(!defined('DIR_BASE')) exit;

/**
 * The class UserModel contains functions for the table 'users'.
 */
class UserModel extends Model {
	/**
	* Instance of the table 'users'.
	*/
	private $tableUsers;
	
	/**
	* Create a instance of the table 'users'.
	*/
	public function __construct() {
		$this->tableUsers = new Table('users', array(
			'id',
			'username',
			'password',
			'parent'
		));
	}
	
	/**
	* Checks if the username and password is correct.
	*/
	public function login($username, $passwordEncrypted) {
		$qb = new QueryBuilder();
		$qry = $qb 	-> select('id', 'username', 'parent')
					-> table('users')
					-> where('username', $username)
					-> andd()
					-> where('password', $passwordEncrypted)
					-> build();
		return Database::query($qry);
	}
	
	/**
	* Get's the 'id', 'username' and 'parent' of a specific user.
	*/
	public function get($userid) {
		$qb = new QueryBuilder();
		$qry = $qb 	-> select('id', 'username', 'parent')
					-> table('users')
					-> where('userid', $userid)
					-> build();
		return Database::query($qry);
	}
	
	/**
	* Get's a list with 'id's' and 'username's' from a specific 'parent'.
	*/
	public function getList($userid){
		$qb = new QueryBuilder();
		$qry = $qb	-> select('id', 'username')
					-> table('users')
					-> where('parent', $userid)
					-> build();
		return Database::queryList($qry);
	}
	
	/**
	* Change specific values.
	*/
	public function edit($values) {
		$this->tableUsers->store($values);
	}
}

?>